<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>WebAPI Test</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
  </head>
  <body id="body">
    <div>
        <h3>猜数字游戏</h3>
        玩家请输入一个 1 - 10 的数字： 
        <input type="text" id="input_number"><br>
        <input type="button" value="查看结果" onclick="selectByJQuery()">
        <div id="result">

        </div>

        <script>
            function selectByJQuery() {
                var number = parseInt(Math.random() * 10) + 1;
                jQuery("#input_number").val(number);
                var inputNumber = jQuery("#input_number").val();
                var msg;
                if(number == parseInt(inputNumber)) {
                    msg = "<h4>恭喜你，猜对了</h4>";
                }else {
                    msg = "<h4>猜错了，正确的数字是" + number + "</h4>";
                }
                jQuery("#result").html(msg);
            }




            function select1() {
                //产生随机数
                var number = parseInt(Math.random() * 10) + 1;
                var inputNumber = document.getElementById("input_number").value;
                var msg;
                if(number == parseInt(inputNumber)) {
                    msg = "<h4>恭喜你，猜对了</h4>";
                }else {
                    msg = "<h4>猜错了，正确的数字是" + number + "</h4>";
                }
                document.getElementById("result").innerText = msg;
            }
        </script>
    </div>


    <!-- <input type="button" value="更换图片" onclick="change()"/>

    <style>
      html {
        width: 100%;
        height: 100%;
      }
      body {
        height: 100%;
        width: 100%;
        background-image: url(https://img2.baidu.com/it/u=1332592354,1195654486&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500);
        background-repeat: no-repeat;
        background-position: center center;
        background-size: cover;
      }
      input {
        width: 200px;
        height: 100px;
      }
    </style>
    <script>
      function change() {
        jQuery("body").css("background-image", 
        "url(https://img0.baidu.com/it/u=3007501660,4148393477&fm=253&fmt=auto&app=138&f=JPEG?w=563&h=500)");
      }
    </script> -->
  </body>
</html>
